import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { AuditTConst } from "src/consts/audit_template_const";
import { PopupName } from "src/consts/popup_const";
@Component({})
export default class AuditTBusinessPanel extends MyVue {
    name: string = 'MemberPanel';
    accData: any;
    leadData: any;
    memberData: any;
    footerFlag: boolean = true;
    accSelect: Boolean;
    leadSelect: Boolean;
    memSelect: Boolean;

    initData(that?: any): void {
        that.accData = {};
        that.leadData = {};
        that.memberData = {};
        that.accSelect = false;
        that.leadSelect = false;
        that.memSelect = false;
        if (WLStore().state.auditTRole.type == "role_edit")
            switch (WLStore().state.auditTRole.value_type) {
                case "user":
                    that.accSelect = true
                    that.accData = WLStore().state.auditTRole
                    break;
                case "leader":
                    that.leadSelect = true
                    break;
                case "role":
                    that.memSelect = true
                    that.memberData = WLStore().state.auditTRole
                    break;
            }
    }

    mounted(): void {

    }

    editRole(): void {
        var sendData: any = {}

        if (this.accSelect) {
            if (isNoEmptyObject(this.accData)) {
                sendData.type = "normal"
                if (isString(this.accData.name)) {
                    sendData.value = this.accData.id
                    sendData.value_name = this.accData.name
                } else {
                    sendData.value = this.accData.name.id
                    sendData.value_name = this.accData.name.name
                }
                sendData.value_type = "user"
            }
            else {
                WLMessage("没有选择账号", "warning")
                return
            }
        } else if (this.leadSelect) {
            sendData.type = "normal"
            sendData.value = "-1"
            sendData.value_name = "上级领导"
            sendData.value_type = "leader"
        } else if (this.memSelect) {
            if (isNoEmptyObject(this.memberData)) {
                sendData.type = "normal"
                if (isString(this.memberData.name)) {
                    sendData.value = this.memberData.id
                    sendData.value_name = this.memberData.name
                } else {
                    sendData.value = this.memberData.name.id
                    sendData.value_name = this.memberData.name.name
                    sendData.value_type = "role"
                }
            } else {
                WLMessage("没有选择角色", "warning")
                return
            }
        } else {
            WLLib.panel(PopupName.AuditT_Role).close()
            return
        }

        sendData.ind = WLStore().state.auditTRole.ind
        if (isNoEmptyObject(sendData)) {
            WLCommit(AuditTConst.CommitRole, sendData)
        }
    }

    selectType(type: String): void {
        this.accSelect = false;
        this.leadSelect = false;
        this.memSelect = false;
        switch (type) {
            case 'acc':
                this.accSelect = true
                break;
            case 'lead':
                this.leadSelect = true
                break;
            case 'member':
                this.memSelect = true
                break;
        }
    }

    roleChange(): void {
        this.accSelect = false;
        this.leadSelect = false;
        this.memSelect = true;
    }

    accChange(): void {
        this.leadSelect = false;
        this.memSelect = false;
        this.accSelect = true;
    }
}